package restaurant.core;

import java.util.ArrayList;

public class Request {
	private int table;
	private ArrayList<Integer> meals;
	
	public Request(int table) {
		this.table = table;
		this.meals = new ArrayList<Integer>();
	}
	
	public Request(int table, ArrayList<Integer> meals) {
		this.table = table;
		this.meals = meals;
	}
	
	public ArrayList<Integer> getMeals() {
		return meals;
	}
	
	public int getTable() {
		return table;
	}
	
	public void setTable(int table) {
		this.table = table;
	}
	
	public void addMeal(Integer meal) {
		this.meals.add(meal);
	}
	
	public static boolean tryParse(String request) {
		if(request.split(" ").length < 2)
			return false;
		return true;
	}
	
	public static Request parseRequest(String request) {
		if(request.split(" ").length == 1)
			return null;
		
		String[] pieces = request.split(" ");
		Request r = new Request(Integer.parseInt(pieces[0]));
		for(int i = 1; i < pieces.length; i++) {
			r.addMeal(Integer.parseInt(pieces[i]));
		}
		return r;
	}
	
	@Override
	public String toString() {
		String toReturn = table + "";
		for (Integer i : this.meals) {
			toReturn += " " + i;
		}
		return toReturn;
	}
	
	public boolean isEmpty() {
		if(this.table == -1 && this.meals.isEmpty())
			return true;
		return false;
	}
}